package com.dazzle.core.service.impl;

import java.io.Serializable;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import com.dazzle.core.dao.GenericDao;
import com.dazzle.core.service.GenericService;
import com.dazzle.core.util.query.PagingBean;
import com.dazzle.core.util.query.QueryFilter;


/**
 * Manager基类，调用GenericDAO实现实体的CRUD操作
 * 可以在app-service.xml中按以下方式配置使用：
 * <pre>
 * 	&lt;bean id="appUserManager" parent="txProxyTemplate"&gt;
 *		&lt;property name="target"&gt;
 *		&lt;bean class="com.ht.test.service.impl.AppUserManagerImpl" autowire="byName"&gt;
 *				&lt;constructor-arg ref="appUserDAO"/&gt;
 *			&lt;/bean&gt;
 *		&lt;/property&gt;
 *	&lt;/bean&gt;
 * </pre>
 * @author
 * @param <T> 实体类型
 * @param <PK> 实体主键类型
 */
@Service
public class GenericServiceImpl<T, PK extends Serializable> implements GenericService<T, PK> {
    /**
     * Log variable for all child classes. Uses LogFactory.getLog(getClass()) from Commons Logging
     */
    protected final Log log = LogFactory.getLog(getClass());

    /**
     * GenericDao instance, set by constructor of this class
     */
    protected GenericDao<T, PK> genericDao;

    /**
     * Public constructor for creating a new GenericManagerImpl.
     * @param genericDao the genericDao to use for persistence
     */
    public GenericServiceImpl(final GenericDao<T, PK> genericDao) {
        this.genericDao = genericDao;
    }

	public T save(T entity) {
		return genericDao.save(entity);
	}

	public T merge(T entity) {
		return genericDao.merge(entity);
	}

	public T get(PK id) {
		return genericDao.get(id);
	}

	public void remove(PK id) {
		genericDao.remove(id);
	}

	public void remove(T entity) {
		genericDao.remove(entity);
	}

	public void evict(T entity) {
		genericDao.evict(entity);
	}

	public List<T> getAll() {
		return genericDao.getAll();
	}

	public void flush() {
		genericDao.flush();
	}

	public List<T> getAll(PagingBean pb) {
		return genericDao.getAll(pb);
	}

	public List<T> getAll(QueryFilter filter) {
		return genericDao.getAll(filter);
	}

	public List<T> findByHql(String hql, Object[] objs) {
		return genericDao.findByHql(hql, objs);
	}

	public List<T> findByHql(String hql, Object[] objs, PagingBean pb) {
		return genericDao.findByHql(hql, objs, pb);
	}

	public List<T> findByHql(String hql, Object[] objs, int firstResult,int pageSize) {
		return genericDao.findByHql(hql, objs, firstResult, pageSize);
	}

    

}
